/* TODO 公共的头部JS文件 */
function renderTime() {
    const left = document.querySelector(".left")
    const time = new Date();
    const yea = time.getFullYear();
    const mon = time.getMonth() + 1;
    const day = time.getDate();
    const hou = time.getHours();
    const min = time.getMinutes()
    const sec = time.getSeconds();
    const tt = `${yea}年${mon}月${day}日${hou}时${min}分${sec}秒`
    left.innerHTML = tt;
    setInterval(() => {
        const left = document.querySelector(".left")
        const time = new Date();
        const yea = time.getFullYear();
        const mon = time.getMonth() + 1;
        const day = time.getDate();
        const hou = time.getHours();
        const min = time.getMinutes()
        const sec = time.getSeconds();
        const tt = `${yea}年${mon}月${day}日${hou}时${min}分${sec}秒`
        left.innerHTML = tt;
    }, 1000)
}
renderTime()


//动态显示登录用户名
function showNickName(){
    const nickname = document.getElementById("nickname")
    const avatar = document.getElementById("avatar")
    const userInfo = JSON.parse(sessionStorage.getItem("userInfo"))
    avatar.src = userInfo.avrtor
    nickname.innerText = userInfo.name
}
showNickName();


//动态显示退出按钮
function showLogout(){
    const avatar = document.getElementById("avatar")
    const logout = document.getElementById("logout")
    //鼠标移入avatar显示和隐藏
    avatar.addEventListener("mouseenter",()=>{
        logout.style.display = "block"
    })
    avatar.addEventListener("mouseleave",()=>{
        setTimeout(()=>{
            logout.style.display = "none"
        },2000)
    })
}
showLogout();
